<template>
  <div>
    <commonBox one="订单管理" tow="订单列表"> </commonBox>
    <el-card>
      <el-row>
        <el-col :span="8">
          <el-input
            placeholder="请输入内容"
            v-model="orderinfo.query"
            class="input-with-select"
          >
            <el-button slot="append" icon="el-icon-search"></el-button>
          </el-input>
        </el-col>
      </el-row>
      <!-- 表格 -->
      <el-table :data="listdata" style="width: 100%" border stripe>
        <el-table-column type="index" label="#"> </el-table-column>
        <el-table-column prop="order_number" label="订单编号">
        </el-table-column>
        <el-table-column prop="order_price" label="订单价格" width="100px">
        </el-table-column>
        <el-table-column prop="order_pay" label="是否付款" width="130px">
          <template slot-scope="scope">
            <el-tag v-if="scope.row.order_pay == '0'" type="danger">否</el-tag>
            <el-tag v-else>是</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货" width="100px">
        </el-table-column>

        <el-table-column prop="create_time" label="下单时间" width="180px">
        </el-table-column>
        <el-table-column label="操作" width="200px">
          <template slot-scope="scope">
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="mini"
              @click="addchangbox"
              >编辑</el-button
            >
            <el-button
              type="danger"
              icon="el-icon-warning"
              size="mini"
              @click="addcheck"
              >查看</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="orderinfo.pagenum"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="orderinfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-card>
    <!-- 修改弹框 -->
    <el-dialog
      title="修改地址"
      :visible.sync="adddialogVisible"
      @close="addcolse"
      width="50%"
    >
      <!-- 表单信息 -->
      <el-form
        :model="addfrominfo"
        :rules="addrules"
        ref="addref"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="省市县/区" prop="selectchangname">
          <!-- 级联选择器 -->
          <el-cascader
            v-model="addfrominfo.selectchangname"
            :options="Citydata"
            :props="adddploy"
          ></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="changname">
          <el-input v-model="addfrominfo.changname"></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="adddialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="adddialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <!-- 查看弹框 -->
    <el-dialog title="查看物流" :visible.sync="addcheckinfo" width="50%">
      <!-- 时间线 -->
      <el-timeline>
        <el-timeline-item
          v-for="(activity, index) in checklist"
          :key="index"
          :timestamp="activity.time"
        >
          {{ activity.context }}
        </el-timeline-item>
      </el-timeline>
      <span slot="footer" class="dialog-footer">
        <el-button @click="addcheckinfo = false">取 消</el-button>
        <el-button type="primary" @click="addcheckinfo = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>
<script>
import Citydata from "./citydata";
export default {
  data() {
    return {
      // 订单参数
      orderinfo: {
        query: "",
        pagenum: 1,
        pagesize: 5,
        user_id: "",
      },
      //   表格数据
      listdata: [],
      total: 0,
      //   修改弹框boolear
      adddialogVisible: false,
      //   表单信息
      addfrominfo: {
        selectchangname: [],
        changname: "",
      },
      //   表单的验证规则
      addrules: {
        selectchangname: [
          { required: true, message: "请选择地址", trigger: "blur" },
        ],
        changname: [
          { required: true, message: "请输入详细地址", trigger: "blur" },
        ],
      },
      //   级联选择器配置对象
      adddploy: {
        expandTrigger: "hover",
      },
      Citydata,
      //   查看物流信息
      addcheckinfo: false,
      //   物流信息数据
      checklist: [],
    };
  },
  created() {
    this.getorderlist();
  },
  methods: {
    async getorderlist() {
      const { data: res } = await this.$http.get("orders", {
        params: this.orderinfo,
      });
      console.log(res);
      this.listdata = res.data.goods;
      this.total = res.data.total;
    },
    // 每页的大小
    handleSizeChange(val) {
      this.orderinfo.pagesize = val;
      this.getorderlist();
    },
    // 当前页面
    handleCurrentChange(val) {
      this.orderinfo.pagenum = val;
      this.getorderlist();
    },
    // 修改信息
    addchangbox() {
      this.adddialogVisible = true;
    },
    // 关闭弹框修改地址
    addcolse() {
      this.$refs.addref.resetFields();
    },
    // 查看物流信息
    async addcheck() {
    //   const { data: res } = await this.$http.get("/kuaidi/804909574412544580");
    //   console.log(res);
    //   this.checklist = res.data;
      this.addcheckinfo = true;
    },
  },
};
</script>

 <style lang='less' scoped>
// @import "../../assets/timeline/timeline.css";
// @import "../../assets/timeline-item/timeline-item.css";

.el-row {
  margin-bottom: 10px;
}
.el-cascader {
  width: 100%;
}
</style>